Skip to main content

Keywords

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

Definition

a keyword is a special word that is part of Python's syntax. They are not functions, methods, or objects. They define how the language is structured and executed.

CategoryExamplesDescription
Control flowif, elif, else, for, while, break, continue, return, yieldManage loops and decision-making
Structure and definitionsdef, class, lambda, with, asDefine functions, classes, and contexts
Logical and comparisonand, or, not, is, inCombine or compare values
Exception handlingtry, except, finally, raise, assertHandle errors and enforce conditions
Import and namespaceimport, from, global, nonlocal, delManage scope and module access
Special purposeTrue, False, None, pass, await, async, match, caseLanguage-level constants or syntax keywords